home *** CD-ROM | disk | FTP | other *** search
/ Aminet 5 / Aminet 5 - March 1995.iso / Aminet / text / misc / pcal_4_5.lha / pcal / pscalendar < prev    next >
Text File  |  1994-10-16  |  5KB  |  294 lines

  1. #!/bin/csh -f
  2. #
  3. # [Here it is... the original shell script and PostScript boilerplate that
  4. # would eventually become "pcal".  Modified slightly by A.W. Rogers to
  5. # correct bug in leap year algorithm, suppress the illegible weekday names
  6. # in the small calendars, use the more common "-d" flag (instead of "-P") to
  7. # specify line printer destination, and default to the current month/year.]
  8. #
  9. # Original From: patwood@unirot.UUCP (Patrick Wood)
  10. # The following is a PostScript program to print calendars.  It doesn't
  11. # work on or before 1752.
  12. # Shell stuff added 3/9/87 by King Ables
  13. # Made pretty by tjt 1988
  14. #
  15. # Tim Tessin - Lawrence Livermore National Laboratory 
  16. # tjt@tis.llnl.gov
  17. # Phone: (415) 423-4560 / 422-8971
  18. # Run like the following: pscalendar -Pstrudel 4 1988     - for April 1988
  19. #
  20. set printer="cat"
  21.  
  22. top:
  23. if ($#argv > 0) then
  24.     switch ("$argv[1]")
  25.         case -d*:
  26.         case -P*:
  27.             set printer="lp "`echo $argv[1] | sed s/-P/-d/`
  28.             shift argv
  29.             goto top
  30.         case *:
  31.             if ($?month) then
  32.                 set year="$argv[1]"
  33.             else if ($?year) then
  34.                 echo "usage: $0 [-Pprinter] month year"
  35.                 exit 1
  36.             else
  37.                 set month="$argv[1]"
  38.             endif
  39.             shift argv
  40.             goto top
  41.     endsw
  42. endif
  43.  
  44. if ($?year) then
  45. else 
  46.     @ month = `date +%m`
  47.     @ year = `date +%Y`
  48. endif
  49.  
  50. if ($year < 1900) then
  51.     @ year += 1900
  52. endif
  53.  
  54. cat <<END-OF-CALENDAR | $printer
  55. %!PS-Adobe-1.0
  56. %%BoundingBox: 0 0 612 792
  57. %%Orientation: Landscape
  58.  
  59. % PostScript program to draw calendar
  60. % Copyright (C) 1987 by Pipeline Associates, Inc.
  61. % Permission is granted to modify and distribute this free of charge.
  62.  
  63. % /month should be set to a number from 1 to 12
  64. % /year should be set to the year you want
  65. % you can change the title and date fonts, if you want
  66. % we figure out the rest
  67. % won't produce valid calendars before 1800 (weird stuff happened
  68. % in September of 1752)
  69.  
  70. /month $month def
  71. /year $year def
  72. /titlefont /Times-Bold def
  73. /dayfont /Helvetica-Bold def
  74.  
  75. /month_names [ (January) (February) (March) (April) (May) (June) (July)
  76.         (August) (September) (October) (November) (December) ] def
  77.  
  78. /prtnum { 3 string cvs show} def
  79.  
  80. /drawgrid {        % draw calendar boxes
  81.     dayfont findfont 10 scalefont setfont
  82.     0 1 6 {
  83.         dup dup 100 mul 40 moveto
  84.         submonth 0 eq {
  85.             [ (Sunday) (Monday) (Tuesday) (Wednesday)
  86.               (Thursday) (Friday) (Saturday) ] exch get
  87.             100 center
  88.         } if
  89.         100 mul 35 moveto
  90.         1.0 setlinewidth
  91.         0 1 5 {
  92.             gsave
  93.             100 0 rlineto 
  94.             0 -80 rlineto
  95.             -100 0 rlineto
  96.             closepath stroke
  97.             grestore
  98.             0 -80 rmoveto
  99.         } for
  100.     } for
  101. } def
  102.  
  103. /drawnums {        % place day numbers on calendar
  104.     dayfont findfont 30 scalefont setfont
  105.     /start startday def
  106.     /days ndays def
  107.     start 100 mul 5 add 10 rmoveto
  108.     1 1 days {
  109.         /day exch def
  110.         gsave
  111.         day start add 7 mod 0 eq
  112.         {
  113.             submonth 0 eq
  114.             {
  115.                 .8 setgray
  116.             } if
  117.         } if
  118.         day start add 7 mod 1 eq
  119.         {
  120.             submonth 0 eq
  121.             {
  122.                 .8 setgray
  123.             } if
  124.         } if
  125.         day prtnum
  126.         grestore
  127.         day start add 7 mod 0 eq
  128.         {
  129.             currentpoint exch pop 80 sub 5 exch moveto
  130.         }
  131.         {
  132.             100 0 rmoveto
  133.         } ifelse
  134.     } for
  135. } def
  136.  
  137. /drawfill {        % place fill squares on calendar
  138.     /start startday def
  139.     /days ndays def
  140.     0 35 rmoveto
  141.     1.0 setlinewidth
  142.     0 1 start 1 sub {
  143.         gsave
  144.         .9 setgray
  145.         100 0 rlineto 
  146.         0 -80 rlineto
  147.         -100 0 rlineto
  148.         closepath fill
  149.         grestore
  150.         100 0 rmoveto
  151.     } for
  152.     submonth 1 eq
  153.     {
  154.         /lastday 42 def
  155.         600 -365 moveto
  156.     }
  157.     {
  158.         /lastday 40 def
  159.         400 -365 moveto
  160.     } ifelse
  161.     lastday -1 ndays start 1 add add
  162.     {
  163.         /day exch def
  164.         gsave
  165.         .9 setgray
  166.         100 0 rlineto 
  167.         0 -80 rlineto
  168.         -100 0 rlineto
  169.         closepath fill
  170.         grestore
  171.         day 7 mod 1 eq
  172.         {
  173.             600 -365 80 add moveto
  174.         }
  175.         {
  176.             -100 0 rmoveto
  177.         } ifelse
  178.     } for
  179. } def
  180.  
  181. /isleap {        % is this a leap year?
  182.     year 4 mod 0 eq        % multiple of 4
  183.     year 100 mod 0 ne     % not century
  184.     year 400 mod 0 eq or and    % unless it's divisible by 400
  185. } def
  186.  
  187. /days_month [ 31 28 31 30 31 30 31 31 30 31 30 31 ] def
  188.  
  189. /ndays {        % number of days in this month
  190.     days_month month 1 sub get
  191.     month 2 eq    % Feb
  192.     isleap and
  193.     {
  194.         1 add
  195.     } if
  196. } def
  197.  
  198. /startday {        % starting day-of-week for this month
  199.     /off year 2000 sub def    % offset from start of "epoch"
  200.     off
  201.     off 4 idiv add        % number of leap years
  202.     off 100 idiv sub    % number of centuries
  203.     off 400 idiv add    % number of 400-year intervals
  204.     6 add 7 mod 7 add     % offset from Jan 1 2000
  205.     /off exch def
  206.     1 1 month 1 sub {
  207.         /idx exch def
  208.         days_month idx 1 sub get
  209.         idx 2 eq
  210.         isleap and
  211.         {
  212.             1 add
  213.         } if
  214.         /off exch off add def
  215.     } for
  216.     off 7 mod        % 0--Sunday, 1--monday, etc.
  217. } def
  218.  
  219. /center {        % center string in given width
  220.     /width exch def
  221.     /str exch def width str 
  222.     stringwidth pop sub 2 div 0 rmoveto str show
  223. } def
  224.  
  225. /calendar
  226. {
  227.     titlefont findfont 48 scalefont setfont
  228.     0 60 moveto
  229.     /month_name month_names month 1 sub get def
  230.     month_name show
  231.     /yearstring year 10 string cvs def
  232.     700 yearstring stringwidth pop sub 60 moveto
  233.     yearstring show
  234.  
  235.     0 0 moveto
  236.     drawnums
  237.  
  238.     0 0 moveto
  239.     drawfill
  240.  
  241.     0 0 moveto
  242.     drawgrid
  243. } def
  244.  
  245. 90 rotate
  246. 50 -120 translate
  247. /submonth 0 def
  248. calendar
  249. month 1 sub 0 eq
  250. {
  251.     /lmonth 12 def
  252.     /lyear year 1 sub def
  253. }
  254. {
  255.     /lmonth month 1 sub def
  256.     /lyear year def
  257. } ifelse
  258. month 1 add 13 eq
  259. {
  260.     /nmonth 1 def
  261.     /nyear year 1 add def
  262. {
  263.     /nmonth month 1 add def
  264.     /nyear year def
  265. } ifelse
  266. /submonth 1 def
  267. /year lyear def
  268. /month lmonth def
  269. 500 -365 translate
  270. gsave
  271. .138 .138 scale
  272. 10 -120 translate
  273. calendar
  274. grestore
  275. /submonth 1 def
  276. /year nyear def
  277. /month nmonth def
  278. 100 0 translate
  279. gsave
  280. .138 .138 scale
  281. 10 -120 translate
  282. calendar
  283. grestore
  284.  
  285. showpage
  286.  
  287. END-OF-CALENDAR
  288.  
  289. exit 0
  290.